#include "Arduino.h"
//#include "Adafruit_GFX_Library/Adafruit_GFX.h"    // Core graphics library
//#include "Adafruit_ST7789/Adafruit_ST7789.h" // Hardware-specific library for ST7789
//#include "SPI.h"
#include "App/App.h"
#include "HAL/HAL.h"
#include "lvgl/lvgl.h"
#include "lv_port/lv_port.h"
#include "lvgl/demos/lv_demos.h"
#include "graphicstest.h"


//Program Size: Code=20658 RO-data=4042 RW-data=184 ZI-data=2576  //2022.08.29

/**
  *@SPI1: SCK->PA5  MISO->PA6  MOSI->PA7
  *@SPI2: SCK->PB13 MISO->PB14 MOSI->PB15
  *@SPI3: SCK->PB3  MISO->PB4  MOSI->PB5
  */

void setup(void) {
	HAL::HAL_Init();
	lv_init();
	lv_port_init();
	
	lv_demo_keypad_encoder();
//	lv_demo_benchmark();
//	App_Init();
	
	
	
//  Serial.begin(9600);
//	HAL::Memory_DumpInfo();
	
  Serial.print("Hello! ST7789 TFT Test...");

//  tft.begin();//tft.init(240, 240);   // initialize a ST7789 chip, 240x240 pixels

  Serial.println("Initialized.\r\n");

//  uint16_t time = millis();
//  tft.fillScreen(tft.COLOR_BLACK);
//  time = millis() - time;

//  Serial.println(time, DEC);
//  delay(500);
	
  Serial.println("done");
	
//  delay(1000);
}

void loop() {
	
//	Serial.println("demo begin.");
//	testDemo();

//	Serial.println("demo end.");
	HAL::HAL_Update();
	lv_task_handler();
	__WFI();
	
	Serial.println("loop end.");
}

/**
  * @brief  Main Function
  * @param  None
  * @retval None
  */
int main(void)
{
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    GPIO_JTAG_Disable();
//  SysClock_Init(F_CPU_128MHz);
    Delay_Init();
    ADCx_Init(ADC1);
    setup();
    for(;;)loop();
}
